package com.four.hospital.service.impl;

import com.four.common.utils.R;
import com.four.hospital.dao.AppointmentDao;
import com.four.hospital.dao.UserDao;
import com.four.hospital.entity.Appointment;
import com.four.hospital.entity.User;
import com.four.hospital.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author:wsy
 * @Date: 2022/01/17/19:09
 * @Description
 */
@Service
public class AppointmentServiceImpl implements AppointmentService {

    @Autowired
    private AppointmentDao appointmentDao;

    @Autowired
    private UserDao userDao;

    /**
     * 预约
     * @param userPhone
     * @param docId
     * @return
     */
    @Override
    public R toAppointment(String userPhone, Integer docId) {
        //根据手机号查询登录人信息
        User user=userDao.findUserByPhone(userPhone);
        //根据医生编号去预约表查询医生是否已经预约满
        int count=appointmentDao.findCout(docId);
        if(count==5){
            return R.error("预约已满");
        }else{
            Appointment appointment = new Appointment();
            appointment.setDocId(docId);
            appointment.setUserId(user.getUserId());
            appointment.setAppStatus(0);
            appointmentDao.addAppointment(appointment);
            return R.ok("预约成功");
        }
    }
}